/*
 * InfoURLDialog.java
 *
 * Creates an Info style JDialog that displays two lines of text, with a URL at the end of the second line.
 * The URL is clickable and will launch a browser using BrowserLauncher()
 *
 * @author Guy Wittig
 * @version 04-Mar-2005
 *
 *   This program is part of MV-Plan
 *   Copywrite 2006 Guy Wittig
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   The GNU General Public License can be read at http://www.gnu.org/licenses/licenses.html
 */

package mvplan.gui;

import mvplan.util.BrowserLauncher;

import java.awt.event.*;
import javax.swing.*;

public class InfoURLDialog extends javax.swing.JDialog {
    
    private java.awt.Cursor oldCursor;
    private String launchURL;
    
    /**
     * Creates new form InfoURLDialog
     * @param parent Parent frame
     * @param modal Modal dialog
     * @param info1 Message string 1
     * @param info2 Message string 2
     * @param info3 URL display string
     * @param launchURL URL as a string
     */
    public InfoURLDialog(java.awt.Frame parent, String title, boolean modal, String info1,String info2, String info3, String launchURL) {
        super(parent, title, modal);
        initComponents();
        oldCursor=getCursor();        
        infoLabel1.setText(info1);
        infoLabel2.setText(info2);
        infoLabel3.setText(info3);
        this.launchURL=launchURL;
        // Set ESCAPE key to close dialog
        KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        Action escapeAction = new AbstractAction(){
                public void actionPerformed(ActionEvent e){
                    dispose();
                }
        };        
        getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
        getRootPane().getActionMap().put("ESCAPE",escapeAction);          
        pack();
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setLocationRelativeTo(parent);
        getRootPane().setDefaultButton(okButton);
        setVisible(true);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        iconPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        infoPanel = new javax.swing.JPanel();
        infoLabel1 = new javax.swing.JLabel();
        buttonPanel = new javax.swing.JPanel();
        okButton = new javax.swing.JButton();
        infoPanel2 = new javax.swing.JPanel();
        infoLabel2 = new javax.swing.JLabel();
        infoLabel3 = new javax.swing.JLabel();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setModal(true);
        setResizable(false);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvplan/resources/metal-Inform.gif")));
        iconPanel.add(jLabel1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        getContentPane().add(iconPanel, gridBagConstraints);

        infoPanel.setLayout(new java.awt.BorderLayout());

        infoLabel1.setText("<INFO-1>");
        infoLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        infoPanel.add(infoLabel1, java.awt.BorderLayout.WEST);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        getContentPane().add(infoPanel, gridBagConstraints);

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        buttonPanel.add(okButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        getContentPane().add(buttonPanel, gridBagConstraints);

        infoLabel2.setText("<INFO-2>");
        infoPanel2.add(infoLabel2);

        infoLabel3.setForeground(java.awt.Color.blue);
        infoLabel3.setText("<INFO-3>");
        infoLabel3.setToolTipText("");
        infoLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                infoLabel3MouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                infoLabel3MouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                infoLabel3MousePressed(evt);
            }
        });

        infoPanel2.add(infoLabel3);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 10, 10);
        getContentPane().add(infoPanel2, gridBagConstraints);

    }// </editor-fold>//GEN-END:initComponents

    private void infoLabel3MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_infoLabel3MousePressed
        BrowserLauncher.openURL(launchURL);
    }//GEN-LAST:event_infoLabel3MousePressed

    private void infoLabel3MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_infoLabel3MouseExited
        setCursor(oldCursor);
    }//GEN-LAST:event_infoLabel3MouseExited

    private void infoLabel3MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_infoLabel3MouseEntered
        java.awt.Cursor handCursor = new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR);
        setCursor(handCursor);
    }//GEN-LAST:event_infoLabel3MouseEntered

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        setVisible(false);
        dispose();
    }//GEN-LAST:event_okButtonActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JPanel iconPanel;
    private javax.swing.JLabel infoLabel1;
    private javax.swing.JLabel infoLabel2;
    private javax.swing.JLabel infoLabel3;
    private javax.swing.JPanel infoPanel;
    private javax.swing.JPanel infoPanel2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton okButton;
    // End of variables declaration//GEN-END:variables
    
}
